<?php

defined( 'IN_DICE' ) or die( 'Access Error!' );

include dirname( __FILE__ ) . '/class.paypal.php';

class paypal implements paypf {

	private $paypal;
	public $moneycode = 'USD';

	public function  __construct( $aSet ) {
		$this->paypal = new paypalop( $aSet );
	}

	public function ordertopf( $aInfo ) { //提交订单至paypal
		$this->paypal->__init( $aInfo['returl'], $aInfo['cancelurl'], $aInfo['notifyurl'] );
		$token = $this->paypal->SetExpressCheckout( $this->moneycode, $aInfo['pamt'], $aInfo['pname'] );
		return $token;
	}

	public function  getorder($token) { //获得一条订单的所有信息
		$aOrder = $this->paypal->GetExpressCheckoutDetails($token);
		return $aOrder;
	}

	public function  givemoney( $aInfo ) { //请求放款,paypal里面是 DOEC接口 $aInfo['']
		$aR = $this->paypal->DoExpressCheckoutPayment( $aInfo['token'], $aInfo['payerid'], $aInfo['pid'], $aInfo['pamt'], $aInfo['pname'], $this->moneycode, $aInfo['ipnurl'] );
		return $aR;
	}


	public function getredirecturl( $token ) {
		return $this->paypal->payUrl . $token;
	}

}